<?php
require_once("database.php");
class xl_hoa_don extends database {
	function danh_sach($vi_tri,$so_luong) {
		$vi_tri=intval($vi_tri);
		$so_luong=intval($so_luong);
		$sql="select * from hoa_don limit $vi_tri,$so_luong";
		$this->setQuery($sql);
		return $this->loadAllRow();
	}
	function so_luong() {
		$sql="select count(*) from hoa_don";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function so_luong_theo_ngay($ngay) {
		$from=$ngay.' 0:0:0';
		$to=$ngay.' 23:59:59';
		$sql="select count(*) from hoa_don where '$from' <= ngay_tao and ngay_tao < '$to'";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function xem($ma) {
		$ma=intval($ma);
		$sql="select * from hoa_don where ma='$ma'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	function xem_hoa_don($ma_hd) {
		$ma_hd=addslashes($ma_hd);
		$sql="select * from hoa_don where ma_hd='$ma_hd'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	function xoa($ma) {
		$ma=intval($ma);
		$sql="delete from hoa_don where ma='$ma'";
		$this->setQuery($sql);
		$this->query();
	}
	function them($ma_hd,$ho_ten,$cmnd,$gioi_tinh,$ngay_sinh,$dia_chi,$email,$dien_thoai,$ngay_tao,$trang_thai,$ghi_chu,$tong_tien,$ho_ten_nguoi_nhan,$dia_chi_nguoi_nhan,$dien_thoai_nguoi_nhan,$ma_cuoc_phi_van_chuyen,$ma_phuong_thuc_thanh_toan) {
		$ma_hd=addslashes($ma_hd);
		$ho_ten=addslashes($ho_ten);
		$cmnd=addslashes($cmnd);
		$dia_chi=addslashes($dia_chi);
		$email=addslashes($email);
		$dien_thoai=addslashes($dien_thoai);
		$ghi_chu=addslashes($ghi_chu);
		$tong_tien=intval($tong_tien);
		$ho_ten_nguoi_nhan=addslashes($ho_ten_nguoi_nhan);
		$dia_chi_nguoi_nhan=addslashes($dia_chi_nguoi_nhan);
		$dien_thoai_nguoi_nhan=addslashes($dien_thoai_nguoi_nhan);
		$ma_cuoc_phi_van_chuyen=addslashes($ma_cuoc_phi_van_chuyen);
		$ma_phuong_thuc_thanh_toan=addslashes($ma_phuong_thuc_thanh_toan);	
		$ngay_sinh= substr($ngay_sinh,6,4).'-'.substr($ngay_sinh,0,2).'-'.substr($ngay_sinh,3,2);
		$sql="INSERT INTO hoa_don(ma_hd,ho_ten,cmnd,gioi_tinh,ngay_sinh,dia_chi,email,dien_thoai,ngay_tao,trang_thai,ghi_chu,tong_tien,ho_ten_nguoi_nhan,dia_chi_nguoi_nhan, dien_thoai_nguoi_nhan,ma_cuoc_phi_van_chuyen,ma_phuong_thuc_thanh_toan) VALUES ('$ma_hd','$ho_ten','$cmnd','$gioi_tinh','$ngay_sinh','$dia_chi','$email','$dien_thoai','$ngay_tao','$trang_thai','$ghi_chu','$tong_tien','$ho_ten_nguoi_nhan', '$dia_chi_nguoi_nhan','$dien_thoai_nguoi_nhan','$ma_cuoc_phi_van_chuyen','$ma_phuong_thuc_thanh_toan')";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat($ma,$ma_hd,$ho_ten,$cmnd,$gioi_tinh,$ngay_sinh,$dia_chi,$email,$dien_thoai,$ngay_tao,$trang_thai,$ghi_chu,$tong_tien,$ho_ten_nguoi_nhan,$dia_chi_nguoi_nhan,$dien_thoai_nguoi_nhan,$ma_cuoc_phi_van_chuyen,$ma_phuong_thuc_thanh_toan) {
		$ma=intval($ma);
		$ma_hd=addslashes($ma_hd);
		$ho_ten=addslashes($ho_ten);
		$cmnd=addslashes($cmnd);
		$dia_chi=addslashes($dia_chi);
		$email=addslashes($email);
		$dien_thoai=addslashes($dien_thoai);
		$ghi_chu=addslashes($ghi_chu);
		$tong_tien=intval($tong_tien);
		$ho_ten_nguoi_nhan=addslashes($ho_ten_nguoi_nhan);
		$dia_chi_nguoi_nhan=addslashes($dia_chi_nguoi_nhan);
		$dien_thoai_nguoi_nhan=addslashes($dien_thoai_nguoi_nhan);
		$ma_cuoc_phi_van_chuyen=addslashes($ma_cuoc_phi_van_chuyen);
		$ma_phuong_thuc_thanh_toan=addslashes($ma_phuong_thuc_thanh_toan);
		$sql="UPDATE hoa_don SET ma_hd= '$ma_hd',ho_ten= '$ho_ten',cmnd= '$cmnd',gioi_tinh= '$gioi_tinh',ngay_sinh= '$ngay_sinh',dia_chi= '$dia_chi',email= '$email',dien_thoai= '$dien_thoai',ngay_tao= '$ngay_tao',trang_thai= '$trang_thai',ghi_chu= '$ghi_chu',tong_tien= '$tong_tien',ho_ten_nguoi_nhan= '$ho_ten_nguoi_nhan',dia_chi_nguoi_nhan= '$dia_chi_nguoi_nhan',dien_thoai_nguoi_nhan= '$dien_thoai_nguoi_nhan',ma_cuoc_phi_van_chuyen= '$ma_cuoc_phi_van_chuyen',ma_phuong_thuc_thanh_toan= '$ma_phuong_thuc_thanh_toan' WHERE ma='$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat_pttt($ma,$ma_phuong_thuc_thanh_toan) {
		$ma=intval($ma);
		$ma_phuong_thuc_thanh_toan=addslashes($ma_phuong_thuc_thanh_toan);
		$sql="UPDATE hoa_don SET ma_phuong_thuc_thanh_toan= '$ma_phuong_thuc_thanh_toan' WHERE ma='$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat_tt($ma_hd,$trang_thai) {
		$ma_hd=addslashes($ma_hd);
		$sql="UPDATE hoa_don SET trang_thai= '$trang_thai' WHERE ma_hd='$ma_hd'";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat_tong_tien($ma,$tong_tien) {
		$ma=intval($ma);
		$tong_tien=intval($tong_tien);
		$sql="UPDATE hoa_don SET tong_tien= '$tong_tien' WHERE ma='$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function tim_kiem ($tu_khoa) {
		$sql="select * from hoa_don where	$ho_ten like %tu_khoa% or 	$dia_chi like %tu_khoa% or 	$email like %tu_khoa% or 	$dien_thoai like %tu_khoa% or 	$ghi_chu like %tu_khoa% or 	$ho_ten_nguoi_nhan like %tu_khoa% or 	$dia_chi_nguoi_nhan like %tu_khoa% or 	$dien_thoai_nguoi_nhan like %tu_khoa% or 	$ma_cuoc_phi_van_chuyen like %tu_khoa% or 	$ma_phuong_thuc_thanh_toan like %tu_khoa%"; 
		$this->setQuery($sql);
		return $this->loadAllRow();	
	}
 }
?>